package com.lavender.transaction.transaction.impl;

import com.lavender.transaction.entity.User;
import com.lavender.transaction.service.UserService;
import com.lavender.transaction.transaction.UserServiceInterface;
import com.lavender.transaction.transaction.AccountServiceInterface;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Slf4j
@Service
public class UserServiceInterfaceImpl implements UserServiceInterface {

    @Autowired
    private UserService userService;

    @Autowired
    private AccountServiceInterface accountServiceInterface;

    @Transactional(rollbackFor = RuntimeException.class)
    @Override
    public String insert() {
        accountServiceInterface.insert();
        insertUser();
        return "ok";
    }

    private void insertUser() {
        User user = new User();
        user.setUserId("admin");
        user.setPassword("123456");
        userService.insert(user);
        throw new RuntimeException("插入失败");
    }

}
